<template>
  <view class="wrap">
    <view class="wrapList" v-if="list && list.length > 0">
      <view class="item" v-for="(item, index) in list" :key="index">
        <view class="top">
          <text>{{
            item.submitTime
              ? transformTimeTwo(
                  new Date(item.submitTime.replace(/\-/g, '/')).getTime(),
                  'minutesdd'
                ).replace(/\//g, '-')
              : ''
          }}</text>
          <text
            :class="[
              'state',
              item.state == 'TODO'
                ? 'active'
                : item.state == 'DOING'
                ? 'doing'
                : item.state == 'DONE'
                ? 'finished'
                : ''
            ]"
          >
            {{
              item.state == 'TODO'
                ? '处理中'
                : item.state == 'DOING'
                ? '处理中'
                : item.state == 'DONE'
                ? '已完成'
                : '已取消'
            }}
          </text>
        </view>
        <view class="min">
          <view class="people">
            <text class="title">申请人：</text>
            <view class="info">
              <text class="infoName">{{ item.patName }}</text>
              <text class="infoName">{{ item.gender == '女性' ? '女' : '男' }}</text>
              <text class="infoName" v-if="item.age">{{ item.age }}岁</text>
            </view>
          </view>
          <view class="people">
            <text class="name">期望就诊医院：</text>
            <text class="hos">{{ item.hospitalName }}</text>
          </view>
          <view class="people">
            <text class="name">期望就诊医生：</text>
            <text class="info">{{ item.doctorName }}</text>
          </view>
        </view>
      </view>
    </view>
    <view class="nodate" v-else>
      <img class="img" src="https://ainengli.hzjrsw.com/jkhx/noData.png" alt="" />
      <view class="nodate_text">
        <text class="name">暂无数据</text>
      </view>
    </view>
  </view>
</template>

<script setup lang="ts">
import { ref } from 'vue'
import { onShow, onLoad } from '@dcloudio/uni-app'
import { hepgreenwayorderList } from '@/api/hmm'
import { transformTimeTwo } from '@/utils/hmm'
import { base_info } from '@/api/moreMessage'
import store from '@/store'
const userInfo = ref({})
const userObj = ref({})
const list = ref([])
const empi = ref('')

onLoad((option) => {
  empi.value = option ? option.empi : ''
})

onShow(() => {
  userInfo.value = uni.getStorageSync('userInfo')
    ? JSON.parse(uni.getStorageSync('userInfo')).patientInfo
    : {}
  userObj.value = uni.getStorageSync('userInfo') ? JSON.parse(uni.getStorageSync('userInfo')) : {}
  if (empi.value) {
    // 判断是否带参数进入页面
    userInfo.value.empi = empi.value
    store.commit('SET_ISNOTICE', true)
    switchPatient()
  }
  init()
})
const init = () => {
  uni.showLoading({
    title: '加载中'
  })
  let param = userObj.value.userId + '/' + userInfo.value.empi
  hepgreenwayorderList(param).then((res) => {
    uni.hideLoading()
    if (res.code == 0) {
      list.value = res.data && res.data.length > 0 ? res.data : []
    }
  })
}
const switchPatient = () => {
  // 切换就诊人
  let params = {
    userId: userObj.value.userId,
    empi: empi.value
  }
  base_info(params).then((res) => {
    const info = Object.assign({}, JSON.parse(uni.getStorageSync('userInfo')))
    info.patientInfo = res.data
    store.commit('SET_USERINFO', info)
  })
}
</script>
<style lang="scss" scoped>
.wrap {
  .wrapList {
    display: inline-block;
    margin-left: 32rpx;
    width: calc(100% - 64rpx);
    margin-bottom: 32rpx;
    .item {
      background: #fff;
      padding: 0 32rpx 24rpx;
      border-radius: 12rpx;
      margin-top: 32rpx;
      .top {
        height: 88rpx;
        line-height: 88rpx;
        position: relative;
        font-size: 28rpx;
        color: #666;
        border-bottom: 1rpx solid #e5e6eb;
        .state {
          position: absolute;
          top: 50%;
          transform: translateY(-50%);
          right: 0;
          padding: 4rpx 16rpx;
          height: 36rpx;
          line-height: 36rpx;
          border-radius: 4rpx;
          font-size: 24rpx;
          color: #666;
          background: #f5f5f5;
          &.active {
            color: #ff503d;
            background: rgba(255, 80, 61, 0.1);
          }
          &.doing {
            color: #5c8eff;
            background: rgba(92, 142, 255, 0.1);
          }
          &.finished {
            color: #00d1b6;
            background: rgba(0, 209, 182, 0.1);
          }
        }
      }
      .min {
        .people {
          margin-top: 24rpx;
          font-size: 28rpx;
          color: #666;
          .title {
            display: inline-block;
            vertical-align: middle;
          }
          .info {
            color: #222;
            display: inline-block;
            vertical-align: middle;
            .infoName {
              display: inline-block;
              vertical-align: middle;
              &:nth-child(2) {
                margin: 0 10rpx;
              }
            }
          }
          .name {
            width: 200rpx;
            display: inline-block;
            vertical-align: top;
          }
          .hos {
            width: calc(100% - 200rpx);
            display: inline-block;
            vertical-align: top;
            font-size: 28rpx;
            color: #222;
          }
        }
      }
    }
  }
  .nodate {
    text-align: center;
    .img {
      display: inline-block;
      width: 320rpx;
      height: 240rpx;
      margin-top: 240rpx;
    }
    .nodate_text {
      .name {
        display: block;
        font-size: 28rpx;
        color: #666;
        text-align: center;
        margin-top: 10rpx;
      }
    }
  }
}
</style>
